
#include "precompiled.h"
#include "tasksui.h"
#include "ui_tasksui.h"

#include "engine.h"
#include "tasks.h"
#include "zones.h"

#include "declarativeextension.h"
#include "script/contextimpl.h"

TasksUI::TasksUI(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::TasksUI)
  ,ext(0)
  ,ctx(0)
{
    ui->setupUi(this);
}

TasksUI::~TasksUI()
{
    delete ext;
    delete ctx;
    delete ui;
}


void TasksUI::reloadApplication()
{
    if (ext != 0)
    {
        ext->stop();
        delete ext;
    }

    ctx = new ContextImpl(info.absoluteDir());
    ext = new DeclarativeExtension(Optra::Extensions::Plugin::application, ctx, info);
    ext->registerObject("tasks", Engine::instance()->tasks());
    ext->registerObject("zones", Engine::instance()->zones());
    //ext->setProperty("tasks", Engine::instance()->tasks());
    ext->start();
}


void TasksUI::start(const QUrl& url)
{
    info = QFileInfo(url.toLocalFile());
    reloadApplication();
}
